/*
 * Pipeline.cpp
 *
 *  Created on: Jul 5, 2012
 *      Author: s131705
 */

#include "Pipeline.h"
#include <sstream>

Pipeline::Pipeline()
{
	commands = new list<Command*>();
}

Pipeline::~Pipeline()
{
 	list<Command*>::iterator it;
	 for( it = commands->begin(); it != commands->end(); it++ )
	 {
	 	delete(*it);
	 }
	delete commands;
}

Command* Pipeline::popCommand()
{
	Command* c = commands->back();
	commands->pop_back();
	return c;
}

bool Pipeline::hadExitCommand()
{
	bool exit = false;
	list<Command*>::iterator it;
	for( it = commands->begin(); it != commands->end(); it++ )
	{
		exit |= (*it)->isExitCommand();
	}
	return exit;
}

string Pipeline::toString()
{
	stringstream ss (stringstream::in | stringstream::out);
	list<Command*>::iterator it;
	for( it = commands->begin(); it != commands->end(); it++ )
	{
		//it->toString();
		ss << (*it)->toString();
	}
	return ss.str();
}
